package cn.tide.question2.question;
/**
 * 第9题多线程示例
 */
public class question9 {
    public static void main(String[] args) {
        Thread t1 = new Thread(new Person());
        Thread t2 = new Thread(new Person());

        t1.start();
        t2.start();
    }

}

class Person implements Runnable{

    public static int ticket = 1000;

    @Override
    public void run() {
        while (true) {
            synchronized ("lock") {
                if (ticket > 0) {
                    System.out.println(Thread.currentThread().getName()+"正在售票，"+"还剩多少张票：" + --ticket);
                } else {
                    break;
                }
            }
        }
    }
}
